#coding=utf-8
import sys, urllib, socket

http_url = 'http://%s.appspot.com/fetch.py'
https_url = 'https://%s.appspot.com/fetch.py'
reverse_url = 'http://%s.jayproxy.com/fetch.py'

urls = {'http':http_url, 'https':https_url, 'reverse':reverse_url}

def print_red(s):
  print '\033[0;31;48m%s\033[0m'%s
  
def check(app_id, type_='http'):
    url = urls[type_]
    
    socket.setdefaulttimeout(5)
    try:
        f = urllib.urlopen(url%app_id)  
    except IOError,e:
        '''
        errno, errstr = sys.exc_info()[:2]
        if str(errstr).find('timed out') !=-1:
            return False
        if str(errstr).find('reset') !=-1:
            return False
        '''
        print e
        return False
    else:
        code = f.getcode()
        #print code
        if code == 200:
            return True
        else:
            return False

if __name__ == '__main__':
    from apps import apps
    for app in apps:
        print_red(app)
        print 'http => %s'%check(app, 'http')
        print 'https => %s'%check(app, 'https')
        print 'reverse => %s\n'%check(app, 'reverse')






